// lazyLoadDirective.js
const lazy = {
  bind(el, binding) {
    el.setAttribute('data-src', binding.value);
    el.src = ''; // 占位图
  },
  inserted(el) {
    const observer = new IntersectionObserver((entries, observer) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          const img = entry.target;
          img.src = img.getAttribute('data-src');
          observer.unobserve(img);
        }
      });
    });
    observer.observe(el);
  }
};

export default lazy;